<template>
  <view class="index-container">
    <view class="banner">
      <swiper 
        class="banner-swiper" 
        circular 
        :indicator-dots="true"
        :autoplay="true"
        :interval="3000"
        :duration="1000"
      >
        <swiper-item v-for="(item, index) in banners" :key="index">
          <image :src="item.image" mode="aspectFill" />
        </swiper-item>
      </swiper>
    </view>

    <view class="category-grid">
      <view 
        class="category-item"
        v-for="(item, index) in categories"
        :key="index"
        @tap="navigateToMenu(item)"
      >
        <image :src="item.icon" mode="aspectFit" />
        <text>{{ item.name }}</text>
      </view>
    </view>

    <view class="recommend-section">
      <view class="section-title">推荐菜品</view>
      <view class="dish-list">
        <view 
          class="dish-item"
          v-for="(item, index) in recommendDishes"
          :key="index"
          @tap="navigateToDish(item)"
        >
          <image :src="item.image" mode="aspectFill" />
          <view class="dish-info">
            <text class="dish-name">{{ item.name }}</text>
            <text class="dish-price">¥{{ item.price }}</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

const banners = ref([
  { image: '/static/banner/1.jpg' },
  { image: '/static/banner/2.jpg' },
  { image: '/static/banner/3.jpg' }
])

const categories = ref([
  { name: '热销', icon: '/static/category/hot.png' },
  { name: '套餐', icon: '/static/category/set.png' },
  { name: '主食', icon: '/static/category/staple.png' },
  { name: '小吃', icon: '/static/category/snack.png' }
])

const recommendDishes = ref([
  {
    id: 1,
    name: '招牌炒饭',
    price: 22,
    image: '/static/dishes/1.jpg'
  },
  {
    id: 2,
    name: '宫保鸡丁',
    price: 32,
    image: '/static/dishes/2.jpg'
  }
])

const navigateToMenu = (category) => {
  uni.navigateTo({
    url: `/pages/menu/index?category=${category.name}`
  })
}

const navigateToDish = (dish) => {
  uni.navigateTo({
    url: `/pages/dish/detail?id=${dish.id}`
  })
}
</script>

<style lang="scss" scoped>
.index-container {
  min-height: 100vh;
  background: #f5f5f5;

  .banner {
    height: 360rpx;
    
    .banner-swiper {
      height: 100%;
      
      image {
        width: 100%;
        height: 100%;
      }
    }
  }

  .category-grid {
    display: flex;
    flex-wrap: wrap;
    padding: 20rpx;
    background: #fff;
    margin: 20rpx 0;

    .category-item {
      width: 25%;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 20rpx 0;

      image {
        width: 80rpx;
        height: 80rpx;
        margin-bottom: 10rpx;
      }

      text {
        font-size: 24rpx;
        color: #333;
      }
    }
  }

  .recommend-section {
    background: #fff;
    padding: 20rpx;

    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      margin-bottom: 20rpx;
    }

    .dish-list {
      display: flex;
      flex-wrap: wrap;
      margin: 0 -10rpx;

      .dish-item {
        width: calc(50% - 20rpx);
        margin: 10rpx;
        background: #fff;
        border-radius: 12rpx;
        overflow: hidden;
        box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.1);

        image {
          width: 100%;
          height: 300rpx;
        }

        .dish-info {
          padding: 16rpx;

          .dish-name {
            font-size: 28rpx;
            color: #333;
          }

          .dish-price {
            font-size: 32rpx;
            color: #f56c6c;
            font-weight: bold;
            margin-top: 8rpx;
          }
        }
      }
    }
  }
}
</style> 